<?php
class Article extends Controller{
    
	function Article(){
		parent::Controller();	
	}		
    
	/**
	 * Load list articles
	 * @author tien.nguyen
	 * @param int $start - default is 0
	 */
    function index($cate_code, $start = 0){
        $this->load->model('Articles_model', null, true);
        $this->load->model('Articles_categories_model', null, true);
        
        $this->load->library('pagination');
       	$cofigPagination = $this->config->item('pagination');

        $config['base_url'] = base_url().'tin_tuc/'.$cate_code;
        $config['total_rows'] = $this->Articles_model->getCountArticle($cate_code);
        $config['per_page'] = 4; 
        $config['uri_segment'] = 3;	
        //echo "<pre>";var_dump($config);die;			//position of params.
        $this->pagination->initialize($config); 
        
        $data['articles'] = $this->Articles_model->getListArticle($cate_code, $this->uri->segment(3)); 
        $data['cateRootCode'] = $this->Articles_categories_model->getCateRoot($cate_code);   
        $data['cateCode'] = $cate_code;    
        $data['cateRootChild'] = $this->Articles_categories_model->getChildForRoot($cate_code);
        // meta 
        $data['meta'] = array(
            		array('name'=>'description', 'content'=>title_cate($data['cateRootCode']['NewsCategoryCode'])),
            		array('name'=>'keywords', 'content'=>title_cate($data['cateRootCode']['NewsCategoryCode']))
            );
        $this->load->view('article/index', $data);
    }    
    
    /**
     * View detail of article
     * @author tien.nguyen
     * @param string $strArticleId
     */
    public function detail($cate_code, $strArticleId){
    	$articleId = get_id($strArticleId);
    	$this->load->model('Articles_model', null, true);
    	$this->load->model('Articles_categories_model', null, true);
    	
    	$data['article'] = $this->Articles_model->getArticle($articleId);
    	$data['article_other'] = $this->Articles_model->getListOtherArticle($cate_code, $articleId);
    	$data['cateRootCode'] = $this->Articles_categories_model->getCateRoot($cate_code);
    	$data['cateCode'] = $cate_code;
    	$data['cateRootChild'] = $this->Articles_categories_model->getChildForRoot($cate_code);
    	// meta 
        $data['meta'] = array(
            		array('name'=>'description', 'content'=>strip_tags($data['article']['NewsShort'])),
            		array('name'=>'keywords', 'content'=>$data['article']['NewsTitle'])
            );
        $data['Title'] = $data['article']['NewsTitle'];
    	$data['Title'] = $data['article']['NewsTitle'];
    	$this->load->view('article/detail', $data);
    }
}